package com.ruoyi.web.controller.background;

import com.ruoyi.background.domain.AppWorkTeamUser;
import com.ruoyi.background.service.IAppWorkTeamUserService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 队伍成员Controller
 *
 * @author susu
 * @date 2024-09-04
 */
@RestController
@RequestMapping("/applet/workTeamUser")
public class AppWorkTeamUserController extends BaseController {
    @Autowired
    private IAppWorkTeamUserService appWorkTeamUserService;

    /**
     * 查询队伍成员列表
     */
    @PreAuthorize("@ss.hasPermi('applet:workTeamUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppWorkTeamUser appWorkTeamUser) {
        startPage();
        List<AppWorkTeamUser> list = appWorkTeamUserService.selectAppWorkTeamUserList(appWorkTeamUser);
        return getDataTable(list);
    }

    /**
     * 导出队伍成员列表
     */
    @PreAuthorize("@ss.hasPermi('applet:workTeamUser:export')")
    @Log(title = "队伍成员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppWorkTeamUser appWorkTeamUser) {
        List<AppWorkTeamUser> list = appWorkTeamUserService.selectAppWorkTeamUserList(appWorkTeamUser);
        ExcelUtil<AppWorkTeamUser> util = new ExcelUtil<AppWorkTeamUser>(AppWorkTeamUser.class);
        util.exportExcel(response, list, "队伍成员数据");
    }

    /**
     * 获取队伍成员详细信息
     */
    @PreAuthorize("@ss.hasPermi('applet:workTeamUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appWorkTeamUserService.selectAppWorkTeamUserById(id));
    }

    /**
     * 新增队伍成员
     */
    @PreAuthorize("@ss.hasPermi('applet:workTeamUser:add')")
    @Log(title = "队伍成员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppWorkTeamUser appWorkTeamUser) {
        return toAjax(appWorkTeamUserService.insertAppWorkTeamUser(appWorkTeamUser));
    }

    /**
     * 修改队伍成员
     */
    @PreAuthorize("@ss.hasPermi('applet:workTeamUser:edit')")
    @Log(title = "队伍成员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppWorkTeamUser appWorkTeamUser) {
        return toAjax(appWorkTeamUserService.updateAppWorkTeamUser(appWorkTeamUser));
    }

    /**
     * 删除队伍成员
     */
    @PreAuthorize("@ss.hasPermi('applet:workTeamUser:remove')")
    @Log(title = "队伍成员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appWorkTeamUserService.deleteAppWorkTeamUserByIds(ids));
    }
}
